package com.chat.wesocket.entity;

import com.alibaba.fastjson2.JSON;
import lombok.NoArgsConstructor;
import org.springframework.web.socket.TextMessage;

import java.util.HashMap;

@NoArgsConstructor
public class WsMessage extends HashMap<String, Object> {
    public static final String EVENT_NAME = "eventName";
    public static final String EVENT_NEW_APPLICATION = "EVENT_NEW_APPLICATION";
    public static final String EVENT_NEW_FRIEND_RELATION_ESTABLISH = "EVENT_NEW_FRIEND_RELATION_ESTABLISH";
    public static final String EVENT_NEW_MESSAGE_RECEIVE = "EVENT_NEW_MESSAGE_RECEIVE";
    public static final String EVENT_VIDEO_INVITE = "EVENT_VIDEO_INVITE";

    public static final String ON_NEGOTIATION_OFFER = "ON_NEGOTIATION_OFFER";
    public static final String EVENT_NEGOTIATION_OFFER = "EVENT_NEGOTIATION_OFFER";
    public static final String ON_NEGOTIATION_ANSWER = "ON_NEGOTIATION_ANSWER";
    public static final String EVENT_NEGOTIATION_ANSWER = "EVENT_NEGOTIATION_ANSWER";

    public static final String ON_CANDIDATE = "ON_CANDIDATE";
    public static final String EVENT_CANDIDATE = "EVENT_CANDIDATE";

    public static final String EVENT_INVITE_CONFIRM = "EVENT_INVITE_CONFIRM";

    public static final String EVENT_STOP_VIDEO = "EVENT_STOP_VIDEO";

    public WsMessage(String eventName) {
        put(EVENT_NAME,eventName);
    }

    public String getEventName() {
        return get(EVENT_NAME).toString();
    }
    public TextMessage toMessage() {
        return new TextMessage(JSON.toJSONString(this));
    }
}
